package com.lanou.service;/*
 * @author 马继耿~
 * @date 2023/10/25 20:05
 * @version 1.0
 * */

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.mapper.MJG_depositMapper;
import com.lanou.pojo.PaymentBillEntity;
import com.lanou.pojo.PaymentDepositEntity;
import com.lanou.service.MJG_depositService;
import com.lanou.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class MJG_depositServiceImpl implements MJG_depositService {
    @Autowired
    private MJG_depositMapper mjg_depositMapper;
    @Override
    public JsonResult deposit(String resourceName) {
        List<PaymentDepositEntity> deposit = mjg_depositMapper.deposit(resourceName);
        PageInfo<PaymentDepositEntity> paymentDepositEntityPageInfo = new PageInfo<>(deposit);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(paymentDepositEntityPageInfo);
        jsonResult.setStatus(200);

        return jsonResult;
    }

    @Override
    public JsonResult deposit(String pageNum, String pageSize) {
        //处理分页查询
        if(pageNum == null || "".equals(pageNum)){
            pageNum="1";
        }
        if(pageSize == null || "".equals(pageSize)){
            pageSize="5";
        }
        PageHelper.startPage(Integer.valueOf(pageNum),Integer.valueOf(pageSize));
        List<PaymentDepositEntity> deposit = mjg_depositMapper.deposit1();
        PageInfo<PaymentDepositEntity> paymentDepositEntityPageInfo = new PageInfo<>(deposit);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(paymentDepositEntityPageInfo);
        jsonResult.setStatus(200);

        return jsonResult;
    }

    @Override
    public JsonResult deposit(String resourceName, String feeUser, String state, String feeItemName, String payType) {
        List<PaymentDepositEntity> deposit = mjg_depositMapper.deposit2(resourceName,feeUser,state,feeItemName,payType);
        PageInfo<PaymentDepositEntity> paymentDepositEntityPageInfo = new PageInfo<>(deposit);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(paymentDepositEntityPageInfo);
        jsonResult.setStatus(200);

        return jsonResult;
    }

    @Override
    public JsonResult selectfeeuser(String resourceName) {
        List<PaymentBillEntity> deposit = mjg_depositMapper.Selectfeeuser(resourceName);
        PageInfo<PaymentBillEntity> paymentBillEntityPageInfo = new PageInfo<>(deposit);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(paymentBillEntityPageInfo);
        jsonResult.setStatus(200);

        return jsonResult;
    }

    @Override
    public void updatastate(String id) {

        long timestamp = System.currentTimeMillis();
        Instant instant = Instant.ofEpochMilli(timestamp);
        LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        String formattedDateTime = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        mjg_depositMapper.updatastate(id,formattedDateTime);
    }
}
